<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style>
    li {
      display: inline-block;
      width: 30px;
      height: 30px;
      line-height: 30px;
      text-align: center;
      border: 1px solid #2c3e50;
      cursor: pointer;
    }
  </style>
</head>
<body>
<!--<script src="eventloop.js"></script>-->

<ul class="list">
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
</ul>
</body>
<script>

  var oList = document.getElementsByClassName('list')[0];
  var oLi = oList.getElementsByTagName('li');
  console.log(oLi);

  for (var i = 0; i < oLi.length; i++) {
    (function (i) {
      oLi[i].onclick = function () {
        console.log(i);
      }
    })(i)
  }

  function bibao() {
    var a = 10; // 一直被引用 就不会被销毁
    return function () {
      return a;
    }
  }

  let fn = bibao();

  console.log(fn());
  console.log(fn());
  console.log(fn());
  console.log(fn());
  console.log(fn());
  console.log(fn());
  console.log(fn());
  // 闭包会造成内存泄漏
  // data(){return {防止变量污染}}

</script>
</html>
